package com.jiao.store.controller;

import com.jiao.store.Vo.CartVO;
import com.jiao.store.service.CardService;
import com.jiao.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("cards")
@RestController
public class CardController extends  BaseController{


    @Autowired
    private CardService cardService;



    @RequestMapping("addCard")
    public JsonResult<Void> addCard(Integer pid, Integer amount, HttpSession session){
        cardService.addToCard(getUidSession(session),pid,amount,getUserNameFromSession(session));
        return new JsonResult<>(Ok);
    }

    @RequestMapping({"","/"})
    public  JsonResult<List<CartVO>> findCard(HttpSession session){

        List<CartVO> data = cardService.getVoByUid(getUidSession(session));

        return new JsonResult<>(Ok,data);
    }



}
